$(function(){
    
    getIndexCount()
    var cityData=null;
    getCity()
    //获取订单详情统计
    function getIndexCount(){
        ajax({
			'url':'/admin/RMStatistics/indexCount',
			'type':'post',
			'data':{},
			'dataType':'json',
			'success':function(data) {
                if(data){
                    $('.month_pass_order_count').text(data.month.passOrderCount);
                    $('.month_pass_order_than').text(data.month.passOrderCount+':'+data.month.orderCount);
                    if(data.month.orderCount==0){
                        $('.month_pass_order_rate').text("0%");
                    }else{
                        var rate=(data.month.passOrderCount/data.month.orderCount*100).toFixed(2);
                        $('.month_pass_order_rate').text(rate+"%");
                    }
                    $('.last_month_pass_order_count').text(data.lastMonth.passOrderCount);
                    $('.last_month_pass_order_than').text(data.lastMonth.passOrderCount+':'+data.lastMonth.orderCount);
                    if(data.lastMonth.orderCount==0){
                        $('.last_month_pass_order_rate').text("0%");
                    }else{
                        var rate=(data.lastMonth.passOrderCount/data.lastMonth.orderCount*100).toFixed(2);
                        $('.last_month_pass_order_rate').text(rate+"%");
                    }
                    $('.quarter_pass_order_count').text(data.quarter.passOrderCount);
                    $('.quarter_pass_order_than').text(data.quarter.passOrderCount+':'+data.quarter.orderCount);
                    if(data.quarter.orderCount==0){
                        $('.quarter_pass_order_rate').text("0%");
                    }else{
                        var rate=(data.quarter.passOrderCount/data.quarter.orderCount*100).toFixed(2);
                        $('.quarter_pass_order_rate').text(rate+"%");
                    }
                    $('.year_pass_order_count').text(data.year.passOrderCount);
                    $('.year_pass_order_than').text(data.year.passOrderCount+':'+data.year.orderCount);
                    if(data.year.orderCount==0){
                        $('.year_pass_order_rate').text("0%");
                    }else{
                        var rate=(data.year.passOrderCount/data.year.orderCount*100).toFixed(2);
                        $('.year_pass_order_rate').text(rate+"%");
                    }

                    $('.month_over_order_count').text(data.month.overOrderCount);
                    $('.month_over_order_than').text(data.month.overOrderCount+':'+data.month.payOrderCount);
                    if(data.month.payOrderCount==0){
                        $('.month_over_order_rate').text("0%");
                    }else{
                        var rate=(data.month.overOrderCount/data.month.payOrderCount*100).toFixed(2);
                        $('.month_over_order_rate').text(rate+"%");
                    }
                    $('.last_month_over_order_count').text(data.lastMonth.overOrderCount);
                    $('.last_month_over_order_than').text(data.lastMonth.overOrderCount+':'+data.lastMonth.payOrderCount);
                    if(data.lastMonth.payOrderCount==0){
                        $('.last_month_over_order_rate').text("0%");
                    }else{
                        var rate=(data.lastMonth.overOrderCount/data.lastMonth.payOrderCount*100).toFixed(2);
                        $('.last_month_over_order_rate').text(rate+"%");
                    }
                    $('.quarter_over_order_count').text(data.quarter.overOrderCount);
                    $('.quarter_over_order_than').text(data.quarter.overOrderCount+':'+data.quarter.payOrderCount);
                    if(data.quarter.payOrderCount==0){
                        $('.quarter_over_order_rate').text("0%");
                    }else{
                        var rate=(data.quarter.overOrderCount/data.quarter.payOrderCount*100).toFixed(2);
                        $('.quarter_over_order_rate').text(rate+"%");
                    }
                    $('.year_over_order_count').text(data.year.overOrderCount);
                    $('.year_over_order_than').text(data.year.overOrderCount+':'+data.year.payOrderCount);
                    if(data.year.payOrderCount==0){
                        $('.year_over_order_rate').text("0%");
                    }else{
                        var rate=(data.year.overOrderCount/data.year.payOrderCount*100).toFixed(2);
                        $('.year_over_order_rate').text(rate+"%");
                    }
                }
			}
	    })
    }
    //获取省份城市信息
    function getCity(){
        ajax({
			'url':'/admin/RMStatistics/getCity',
			'type':'post',
			'data':{},
			'dataType':'json',
			'success':function(data) {
                if(data){
                    cityData=data   
                    for(var i in data){
                        $('select[name=wayuser_pass_province_select],select[name=wayuser_order_pass_province_select],select[name=wayuser_order_over_province_select],select[name=order_pass_province_select],select[name=order_over_province_select]').append('<option value="'+i+'">'+data[i]['name']+'</option>');
                    }                 
                }
			}
	    })
    }
    $('select[name=wayuser_pass_province_select],select[name=wayuser_order_pass_province_select],select[name=wayuser_order_over_province_select],select[name=order_pass_province_select],select[name=order_over_province_select]').on("change",function(e){
        var id=$(this).val();
        $(this).parent().next().find('select').html('<option value="0">请选择城市</option>');
        if(id!=0){
            var cityInfos=cityData[id]['city'];
            for(var i in cityInfos){
                $(this).parent().next().find('select').append('<option value="'+cityInfos[i]['id']+'">'+cityInfos[i]['name']+'</option>');
            }
        }
    })

    $('.wayuser_pass').on("click",function(e){
        getWayuserPass();
    })

     $('.wayuser_order_pass').on("click",function(e){
        getWayuserOrderPass();
    })
    $('.wayuser_order_over').on("click",function(e){
        getWayuserOrderOver();
    })

    $('.order_pass').on("click",function(e){
        getOrderPass();
    })
    $('.order_over').on("click",function(e){
        getOrderOver();
    })
    
})
function getWayuserPass(page){
    var province=$('select[name=wayuser_pass_province_select]').val();
    var city=$('select[name=wayuser_pass_city_select]').val();
    var month=$('select[name=wayuser_pass_month_select]').val();
    if(!page){
        page=1;
    }
    if(province=="0"){
        var content='<tr class="city_channel_content">\
            <td colspan=11>请选择搜索条件</td>\
        </tr>'
        $(".wayuser_pass_content").html(content)  
        return false;
    }
    ajax({
        'url':'/admin/RMStatistics/getWayuserPass?action=getWayuserPass&p='+page,
        'type':'post',
        'data':{province:province,city:city,month:month},
        'dataType':'json',
        'success':function(data) {
            $(".wayuser_pass_content").html('');
            if(data && data.content){
                var content=""
                    for(var i in data.content){
                        if(data.content[i]['nowCount']==0){
                            var nowPassRate=0
                        }else{
                            var nowPassRate=(data.content[i]['nowPassCount']/data.content[i]['nowCount']*100).toFixed(2);
                        }
                        if(data.content[i]['count']==0){
                            var passRate=0
                        }else{
                            var passRate=(data.content[i]['passCount']/data.content[i]['count']*100).toFixed(2);
                        }
                        content+='<tr class="city_channel_content">\
                        <td>'+data.content[i]['province']+'</td>\
                        <td>'+data.content[i]['SZusernum']+'</td>\
                        <td>'+data.content[i]['city']+'</td>\
                        <td>'+data.content[i]['CSusernum']+'</td>\
                        <td>'+data.content[i]['GwCount']+'</td>\
                        <td>'+data.content[i]['wayuserCount']+'</td>\
                        <td>'+data.content[i]['wayuserUseCount']+'</td>\
                        <td>'+data.content[i]['nowPassCount']+'</td>\
                        <td>'+data.content[i]['nowPassCount']+':'+data.content[i]['nowCount']+'</td>\
                        <td>'+nowPassRate+'%</td>\
                        <td>'+passRate+'%</td>\
                    </tr>'
                    } 
                    if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=11>暂无数据</td>\
                        </tr>'
                    }
                    $(".wayuser_pass_content").html(content)          
            }else{
                if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=11>暂无数据</td>\
                        </tr>'
                    }
                    $(".wayuser_pass_content").html(content)
            }
            $(".wayuser_pass_page").html('')
            if(data && data.page){
                $(".wayuser_pass_page").html(data.page)
            }
        }
        
    },true)
}
function getWayuserOrderPass(page){
    var province=$('select[name=wayuser_order_pass_province_select]').val();
    var city=$('select[name=wayuser_order_pass_city_select]').val();
    var month=$('select[name=wayuser_order_pass_month_select]').val();
    if(!page){
        page=1;
    }
    if(province=="0"){
        var content='<tr class="city_channel_content">\
            <td colspan=11>请选择搜索条件</td>\
        </tr>'
        $(".wayuser_order_pass_content").html(content)  
        return false;
    }
    ajax({
        'url':'/admin/RMStatistics/getWayuserOrderPass?action=getWayuserOrderPass&p='+page,
        'type':'post',
        'data':{province:province,city:city,month:month},
        'dataType':'json',
        'success':function(data) {
            $(".wayuser_order_pass_content").html('');
            if(data && data.content){
                var content=""
                    for(var i in data.content){
                        if(data.content[i]['nowCount']==0){
                            var nowPassRate=0
                        }else{
                            var nowPassRate=(data.content[i]['nowPassCount']/data.content[i]['nowCount']*100).toFixed(2);
                        }
                        if(data.content[i]['count']==0){
                            var passRate=0
                        }else{
                            var passRate=(data.content[i]['passCount']/data.content[i]['count']*100).toFixed(2);
                        }
                        content+='<tr class="city_channel_content">\
                        <td>'+data.content[i]['province']+'</td>\
                        <td>'+data.content[i]['SZusernum']+'</td>\
                        <td>'+data.content[i]['city']+'</td>\
                        <td>'+data.content[i]['CSusernum']+'</td>\
                        <td>'+data.content[i]['GwCount']+'</td>\
                        <td>'+data.content[i]['wayuserCount']+'</td>\
                        <td>'+data.content[i]['wayuserUseCount']+'</td>\
                        <td>'+data.content[i]['nowPassCount']+'</td>\
                        <td>'+data.content[i]['nowPassCount']+':'+data.content[i]['nowCount']+'</td>\
                        <td>'+nowPassRate+'%</td>\
                        <td>'+passRate+'%</td>\
                    </tr>'
                    } 
                    if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=11>暂无数据</td>\
                        </tr>'
                    }
                    $(".wayuser_order_pass_content").html(content)          
            }else{
                if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=11>暂无数据</td>\
                        </tr>'
                    }
                    $(".wayuser_order_pass_content").html(content)
            }
            $(".wayuser_order_pass_page").html('')
            if(data && data.page){
                $(".wayuser_order_pass_page").html(data.page)
            }
        }
        
    },true)
}
function getWayuserOrderOver(page){
    var province=$('select[name=wayuser_order_over_province_select]').val();
    var city=$('select[name=wayuser_order_over_city_select]').val();
    var month=$('select[name=wayuser_order_over_month_select]').val();
    if(!page){
        page=1;
    }
    if(province=="0"){
        var content='<tr class="city_channel_content">\
            <td colspan=11>请选择搜索条件</td>\
        </tr>'
        $(".wayuser_order_over_content").html(content)  
        return false;
    }
    ajax({
        'url':'/admin/RMStatistics/getWayuserOrderOver?action=getWayuserOrderOver&p='+page,
        'type':'post',
        'data':{province:province,city:city,month:month},
        'dataType':'json',
        'success':function(data) {
            $(".wayuser_order_over_content").html('');
            if(data && data.content){
                var content=""
                    for(var i in data.content){
                        if(data.content[i]['nowCount']==0){
                            var nowOverRate=0
                        }else{
                            var nowOverRate=(data.content[i]['nowOverCount']/data.content[i]['nowCount']*100).toFixed(2);
                        }
                        if(data.content[i]['count']==0){
                            var overRate=0
                        }else{
                            var overRate=(data.content[i]['overCount']/data.content[i]['count']*100).toFixed(2);
                        }
                        content+='<tr class="city_channel_content">\
                        <td>'+data.content[i]['province']+'</td>\
                        <td>'+data.content[i]['SZusernum']+'</td>\
                        <td>'+data.content[i]['city']+'</td>\
                        <td>'+data.content[i]['CSusernum']+'</td>\
                        <td>'+data.content[i]['GwCount']+'</td>\
                        <td>'+data.content[i]['wayuserCount']+'</td>\
                        <td>'+data.content[i]['wayuserUseCount']+'</td>\
                        <td>'+data.content[i]['nowOverCount']+'</td>\
                        <td>'+data.content[i]['nowOverCount']+':'+data.content[i]['nowCount']+'</td>\
                        <td>'+nowOverRate+'%</td>\
                        <td>'+overRate+'%</td>\
                    </tr>'
                    } 
                    if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=11>暂无数据</td>\
                        </tr>'
                    }
                    $(".wayuser_order_over_content").html(content)          
            }else{
               if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=11>暂无数据</td>\
                        </tr>'
                    }
                    $(".wayuser_order_over_content").html(content) 
            }
            $(".wayuser_order_over_page").html('')
            if(data && data.page){
                $(".wayuser_order_over_page").html(data.page)
            }
        }
        
    },true)
}
function getOrderPass(page){
    var province=$('select[name=order_pass_province_select]').val();
    var city=$('select[name=order_pass_city_select]').val();
    var month=$('select[name=order_pass_month_select]').val();
    if(!page){
        page=1;
    }
    if(province=="0"){
        var content='<tr class="city_channel_content">\
           <td colspan=9>请选择搜索条件</td>\
        </tr>'
        $(".order_pass_content").html(content)  
        return false;
    }
    ajax({
        'url':'/admin/RMStatistics/getOrderPass?action=getOrderPass&p='+page,
        'type':'post',
        'data':{province:province,city:city,month:month},
        'dataType':'json',
        'success':function(data) {
            $(".order_pass_content").html('');
            if(data && data.content){
                var content=""
                    for(var i in data.content){
                        if(data.content[i]['nowCount']==0){
                            var nowPassRate=0
                        }else{
                            var nowPassRate=(data.content[i]['nowPassCount']/data.content[i]['nowCount']*100).toFixed(2);
                        }
                        if(data.content[i]['count']==0){
                            var passRate=0
                        }else{
                            var passRate=(data.content[i]['passCount']/data.content[i]['count']*100).toFixed(2);
                        }
                        content+='<tr class="city_channel_content">\
                        <td>'+data.content[i]['province']+'</td>\
                        <td>'+data.content[i]['SZusernum']+'</td>\
                        <td>'+data.content[i]['city']+'</td>\
                        <td>'+data.content[i]['CSusernum']+'</td>\
                        <td>'+data.content[i]['GwCount']+'</td>\
                        <td>'+data.content[i]['nowPassCount']+'</td>\
                        <td>'+data.content[i]['nowPassCount']+':'+data.content[i]['nowCount']+'</td>\
                        <td>'+nowPassRate+'%</td>\
                        <td>'+passRate+'%</td>\
                    </tr>'
                    } 
                    if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=9>暂无数据</td>\
                        </tr>'
                    }
                    $(".order_pass_content").html(content)          
            }else{
                if(!content){
                        content='<tr class="city_channel_content">\
                            <td colspan=9>暂无数据</td>\
                        </tr>'
                    }
                    $(".order_pass_content").html(content)
            }
            $(".order_pass_page").html('')
            if(data && data.page){
                $(".order_pass_page").html(data.page)
            }
        }
        
    },true)
}
function getOrderOver(page){
    var province=$('select[name=order_over_province_select]').val();
    var city=$('select[name=order_over_city_select]').val();
    var month=$('select[name=order_over_month_select]').val();
    if(!page){
        page=1;
    }
    if(province=="0"){
        var content='<tr class="city_channel_content">\
                                <td colspan=9>请选择搜索条件</td>\
                        </tr>'
        $(".order_over_content").html(content)  
        return false;
    }
    ajax({
        'url':'/admin/RMStatistics/getOrderOver?action=getOrderOver&p='+page,
        'type':'post',
        'data':{province:province,city:city,month:month},
        'dataType':'json',
        'success':function(data) {
            $(".order_over_content").html('');
            if(data && data.content){
                var content=""
                    for(var i in data.content){
                        if(data.content[i]['nowCount']==0){
                            var nowOverRate=0
                        }else{
                            var nowOverRate=(data.content[i]['nowOverCount']/data.content[i]['nowCount']*100).toFixed(2);
                        }
                        if(data.content[i]['count']==0){
                            var overRate=0
                        }else{
                            var overRate=(data.content[i]['overCount']/data.content[i]['count']*100).toFixed(2);
                        }
                        content+='<tr class="city_channel_content">\
                        <td>'+data.content[i]['province']+'</td>\
                        <td>'+data.content[i]['SZusernum']+'</td>\
                        <td>'+data.content[i]['city']+'</td>\
                        <td>'+data.content[i]['CSusernum']+'</td>\
                        <td>'+data.content[i]['GwCount']+'</td>\
                        <td>'+data.content[i]['nowOverCount']+'</td>\
                        <td>'+data.content[i]['nowOverCount']+':'+data.content[i]['nowCount']+'</td>\
                        <td>'+nowOverRate+'%</td>\
                        <td>'+overRate+'%</td>\
                    </tr>'
                    }
                    if(!content){
                        content='<tr class="city_channel_content">\
                                <td colspan=9>暂无数据</td>\
                        </tr>'
                    } 
        
                    $(".order_over_content").html(content)          
            }else{
                if(!content){
                        content='<tr class="city_channel_content">\
                                <td colspan=9>暂无数据</td>\
                        </tr>'
                    } 
        
                    $(".order_over_content").html(content)
            }
            $(".order_over_page").html('')
            if(data && data.page){
                $(".order_over_page").html(data.page)
            }
        }
        
    },true)
}